package com.cy.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.FstCodec;
import org.redisson.codec.JacksonCodec;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private String port;


    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        //拼接redis地址
        String address = "redis://" + host + ":" + port;
        config.useSingleServer().setAddress(address).setDatabase(2);
//        config.setCodec(new FstCodec());

        //创建实例
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
